package com.atguigu.lease.web.admin.controller.apartment;


import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.LeaseTerm;
import com.atguigu.lease.web.admin.service.LeaseTermService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/term")
@Tag(name = "房间租期管理")
public class LeaseTermMapperController {

    @Autowired
    private LeaseTermService leaseTermService;

    @Operation(summary = "查询全部租期列表")
    @GetMapping("/list")
    public Result<List<LeaseTerm>> selectAllLeaseTerm(){

        List<LeaseTerm> list = leaseTermService.list();
        return Result.ok(list);
    }

    @Operation(summary = "保存或更新租期信息")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdateLeaseTerm(@RequestBody LeaseTerm leaseTerm){

        boolean savedOrUpdate = leaseTermService.saveOrUpdate(leaseTerm);
        return  Result.ok(savedOrUpdate);
    }


    @Operation(summary = "根据ID删除租期")
    @DeleteMapping("/deleteById")
    public Result deleteLeaseTermById(@RequestParam Long id){

        boolean byId = leaseTermService.removeById(id);
        return  Result.ok(byId);

    }


}
